// manager/pages/addmerchantstep/index.js
import config from '../../../utils/config';
import { request, uploadFile } from '../../../utils/request';
import util from '../../../common/util';
import WxValidate from '../../../common/WxValidate';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        baseUrl: config.baseUrl,
        activeIndex: 1,
        stepList: [
            {
                id: 1,
                text: "添加商户"
            },
            {
                id: 2,
                text: "添加成员"
            },
            {
                id: 3,
                text: "首次拜访"
            }
        ],
        showCourse: false,
        noRemind: false,
        /* 添加商户 */
        // 行业字典
        industryList: [],
        // 业务字典
        mBusiList: [],
        keynoteList: [],
        // 商户标签
        merchantTag: [],
        latitude: "",
        longitude: "",
        merchantForm: {
            id: "",
            handName: "",
            headPic: "",
            coordinate: "",
            mapAddress: "",
            address: "",
            industry: "",
            businessLabel: "",
            marketingFocus: "",
            merchantLabel: "",
            licenseName: "",
            licensePic: "",
            remark: "",
        },
        /* 添加成员 */
        // 性别字典
        sexList: [],
        // 职位字典
        posList: [],
        // 业务需求字典
        pBusiList: [],
        // 成员标签字典
        memberTag: [],
        memberForm: {
            // 商户id
            merchantId: "",
            // 1-个人，2-商户，3-企业，4-新型农业主体
            merchantType: 2,
            id: "",
            name: "",
            phone: "",
            sex: "",
            idCard: "",
            duties: "",
            businessDemand: "",
            memberLabel: "",
        },
        /* 首次拜访 */
        // 日期限制
        startDate: "",
        endDate: "",
        startDate1: "",
        // 业务字典
        busiList: [],
        visitKeynoteList: [],
        visitReservationBusiList: [],
        // 营销成功
        semResultList: [],
        // 有无
        hasnoList: [],
        visitForm: {
            merchantId: "",
            // 1-个人，2-商户，3-企业，4-新型农业主体
            merchantType: 2,
            coordinate: "",
            mapAddress: "",
            visitPic: "",
            ecardSemResult: "",
            newBusiness: "",
            failReason: "",
            reminderDate: "",
            hasReservationBusi: "",
            reservationBusiType: "",
            appointmentDate: "",

            remark: "",
        },
        // 商户信息
        merchantDetail: {}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            showCourse: wx.getStorageSync('showCourse') != 1
        })
        
        // 获取字典
        this.getDictionaryInfo();
        // 获取当前位置
        this.getLatLng();
        this.initMerchantValidate();
        this.initMemberValidate();
        this.initVisitValidate();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },
    /**
     * 关闭提示
     */
    closeCourse(){
        if(this.data.noRemind){
            wx.setStorageSync('showCourse',1)
        }
        this.setData({
            showCourse: false
        })
    },
    /**
     * 点击复选框操作
     */
    checkboxTap(e){
        // console.log(e.detail.value)
        // let values = e.detail.value;
        this.setData({
            noRemind: !this.data.noRemind
        })
        //this.setData({certificate})
    },
    /**
     * 点击页签
     */
    stepClick(e){
        let { index } = e.detail;
        let { activeIndex } = this.data;
        if(activeIndex < index + 1){
            if(activeIndex == 1 && index == 1){
                wx.showToast({
                    title: '请先添加商户',
                    icon: 'none',
                    duration: 2000
                })
            }
            if(activeIndex == 1 && index == 2){
                wx.showToast({
                    title: '请先添加商户',
                    icon: 'none',
                    duration: 2000
                })
            }
            if(activeIndex == 2 && index == 2){
                wx.showToast({
                    title: '请先添加成员',
                    icon: 'none',
                    duration: 2000
                })
            }
        }
    },

    /**
     * 输入框输入时
     */
    input(e){
        let key = e.target.dataset.key;
        let { activeIndex } = this.data;
        switch(activeIndex){
            case 1: 
                this.setData({
                    ['merchantForm.'+key]: e.detail.value
                })
                break;
            case 2: 
                this.setData({
                    ['memberForm.'+key]: e.detail.value
                })
                break;
            case 3: 
                let { visitForm } = this.data;
                visitForm[key] = e.detail.value;
                if(key == "ecardSemResult"){
                    visitForm.newBusiness = "";
                    visitForm.failReason = "";
                }
                if(key == "hasReservationBusi"){
                    visitForm.reservationBusiType = "";
                    visitForm.appointmentDate = "";
                }
                this.setData({
                    visitForm
                })
                break;
        }      
    },

    /**
     * 选择框变化时
     */
    pickerChagne(e){
        let { key, value } = e.detail;
        let { activeIndex } = this.data;
        switch(activeIndex){
            case 1: 
                this.setData({
                    ['merchantForm.'+key]: value
                })
                break;
            case 2: 
                this.setData({
                    ['memberForm.'+key]: value
                })
                break;
            case 3: 
                this.setData({
                    ['visitForm.'+key]: value
                })
                break;
        }     
    },

    /**
     * 日期选择
     */
    bindDateChange: function(e) {
        let { key } = e.currentTarget.dataset;
        this.setData({
            ['visitForm.'+key]: e.detail.value
        })
    },

    /**
     * 商户标签
     */
    beMerchantTag(e) {
        let { item } =  e.currentTarget.dataset;
        let arr = this.data.merchantForm.merchantLabel?this.data.merchantForm.merchantLabel.split(","):[];
        let index = arr.indexOf(item.dictValue);
        console.log(arr,arr.indexOf(item.dictValue))
        if(index == -1){
            arr.push(item.dictValue);
        }else{
            arr.splice(index,1);
        }
        this.setData({
            'merchantForm.merchantLabel': arr.join(",")
        })
    },

    /**
     * 已开通业务、营销重点选择
     */
    onMerchantCheckboxChange(e) {
        console.log(e)
        let { key, item } = e.currentTarget.dataset;
        let arr = this.data.merchantForm[key]?this.data.merchantForm[key].split(","):[];
        let index = arr.indexOf(item.dictValue);
        if(index != -1){
            arr.splice(index,1);
        }else{
            arr.push(item.dictValue);
        }
        this.setData({
            ['merchantForm.'+key]: arr.join(",")
        });
        if(key == "businessLabel"){
            this.getKeynoteList(this.data.mBusiList);
        }
    },

    // 查看图片
    previewImage(e) {
        let { url } = e.currentTarget.dataset;
        wx.previewImage({
            current: url, // 当前显示图片的http链接
            urls: [url] // 需要预览的图片http链接列表
        })
    },

    /**
     * 获取所属行业、营销重点、商户标签、性别、职位字典
     */
    getDictionaryInfo() {
        request({
            url: "/commonApi/getDictionaryInfo",
            method: "GET",
            data: {
                dictType: "ecard_merchant_industry"
            }
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    industryList: res.data
                })
            }
            return request({
                url: "/commonApi/getDictionaryInfo",
                method: "GET",
                data: {
                    dictType: "ecard_merchant_business_tag"
                }
            })
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    mBusiList: res.data
                })
                this.getKeynoteList(res.data);
            }
            return request({
                url: "/commonApi/getDictionaryInfo",
                method: "GET",
                data: {
                    dictType: "ecard_merchant_tag"
                }
            })
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    merchantTag: res.data
                })
            }
            return request({
                url: "/commonApi/getDictionaryInfo",
                method: "GET",
                data: {
                    dictType: "cif_sex"
                }
            })
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    sexList: res.data
                })
            }
            return request({
                url: "/commonApi/getDictionaryInfo",
                method: "GET",
                data: {
                    dictType: "ecard_merchant_position"
                }
            })
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    posList: res.data
                })
            }
            return request({
                url: "/commonApi/getDictionaryInfo",
                method: "GET",
                data: {
                    dictType: "ecard_personal_business_tag"
                }
            })
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    pBusiList: res.data
                })
            }
            return request({
                url: "/commonApi/getDictionaryInfo",
                method: "GET",
                data: {
                    dictType: "ecard_personal_tag"
                }
            })
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    memberTag: res.data
                })
            }
            return request({
                url: "/commonApi/getDictionaryInfo",
                method: "GET",
                data: {
                    dictType: "ecard_sem_result"
                }
            })
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    semResultList: res.data
                })
            }
            return request({
                url: "/commonApi/getDictionaryInfo",
                method: "GET",
                data: {
                    dictType: "ecard_has_reservation_busi"
                }
            })
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    hasnoList: res.data
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },

    // 获取营销重点
    getKeynoteList(list){
        let keynoteList = [];
        let arr = this.data.merchantForm.businessLabel?this.data.merchantForm.businessLabel.split(","):[];
        let farr = this.data.merchantForm.marketingFocus?this.data.merchantForm.marketingFocus.split(","):[];
        
        list.forEach(item => {
            if(arr.indexOf(item.dictValue)==-1){
                keynoteList.push(item)
            }
        })
        arr.forEach(item => {
            let index = farr.indexOf(item);
            if(index != -1){
                farr.splice(index,1);
            }
        })
        console.log(farr)
        this.setData({
            keynoteList,
            ['merchantForm.marketingFocus']: farr.join(",")
        })
    },

    // 调整定位
    fineLocation(e){
        let that = this;
        wx.chooseLocation({
            latitude: this.data.latitude,
            longitude: this.data.longitude,
            scale: 18,
            success(res){
                console.log(res)
                let latitude = res.latitude;
                let longitude = res.longitude;
                request({
                    url: `/merchantMarketing/calculateDistance`,
                    reqRSAENCRY: true, // 参数是否加密
                    resRSADECRY: false, // 返回值是否解密
                    data: {
                        coordinate: `${that.data.latitude},${that.data.longitude}`,
                        chooseCoordinate: `${latitude},${longitude}`,
                    }
                }).then(res => {
                    if(res.code == 0){
                        that.setData({
                            latitude,
                            longitude
                        })
                        that.getCoordinatePositionInfo(latitude,longitude)
                    }
                }).catch(error => {
                    // console.log(error)
                })
            }
        })
    },
    
    // 获取经纬度
    getLatLng(){
        let that = this;
        wx.getSetting({
            success: (res) => {
                console.log(res)
                if (res.authSetting['scope.userLocation'] == false) {//非初始化进入该页面,且未授权
                    wx.showModal({
                        title: '是否授权当前位置',
                        content: '需要获取您的地理位置，请确认授权',
                        success: function (res) {
                            if (res.confirm) {
                                wx.openSetting({
                                    success: function (data) {
                                        // console.log(data);
                                        if (data.authSetting["scope.userLocation"] == true) {
                                            that.getLocation();
                                        }
                                    }
                                })
                            }
                        }
                    })
                } else {//初始化进入
                    // console.log("KKKKK") 
                    that.getLocation();
                }
            }
        })
    },
    getLocation(){
        const that = this;
        wx.getLocation({
            type: 'gcj02',
            altitude: true,
            isHighAccuracy: true,
            success (res) {
                that.setData({
                    latitude: res.latitude,
                    longitude: res.longitude,
                })
                that.getCoordinatePositionInfo(res.latitude,res.longitude)
            },
            complete: function(res) {
                console.log(res)
                if(res.errMsg == "getLocation:fail auth deny"){
                    // wx.showToast({
                    //     title: '获取定位失败',
                    //     icon: 'none',
                    //     duration: 2000
                    // });
                }
            }
        })
    },
    getCoordinatePositionInfo(latitude,longitude){
        // const that = this;
        let { merchantForm, visitForm } = this.data;
        request({
            url: "/commonApi/getCoordinatePositionInfo",
            method: "GET",
            data: {
                coordinate: `${latitude},${longitude}`
            }
        }).then(res => {
            if(res.code == 0){
                merchantForm.coordinate = `${latitude},${longitude}`;
                merchantForm.mapAddress = res.data.address;
                merchantForm.address = res.data.address;
                visitForm.coordinate = `${latitude},${longitude}`;
                visitForm.mapAddress = res.data.address;
                this.setData({
                    merchantForm,
                    visitForm
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },
    // 商户图片或营业执照图片上传
    uploadImage(e) { // 拍摄或从相册选取上传
        let { key } = e.currentTarget.dataset;
        let that = this;
        wx.chooseImage({
            count: 1, // 默认9
            sizeType: ['compressed'],
            sourceType: ['camera'],
            success(res) {
                wx.compressImage({
                    src: res.tempFilePaths[0], // 图片路径
                    quality: 40, // 压缩质量
                    success(res1) {
                        uploadFile({
                            url: "/commonApi/imageUploadAddWatermark",
                            filePath: res1.tempFilePath,
                            name: "imgfile",
                            formData: {
                                coordinate: that.data.merchantForm.coordinate,
                                watermark: that.data.merchantForm.mapAddress,
                                fileName: key
                            }
                        }).then(res => {
                            if(res.code == 0){
                                that.setData({
                                    ['merchantForm.'+key]: res.data
                                })
                            }
                        }).catch(error => {
                            // console.log(error)
                        })
                    }
                })
            }
        })
    },
    // 保存商户
    saveMerchant(e) {
        // 传入表单数据，调用验证方法
        if (!this.merchantWxValidate.checkForm(this.data.merchantForm)) {
            const error = this.merchantWxValidate.errorList[0]
            this.showModal(error)
            return false
        }
        request({
            url: `/merchantMarketing/addMerchantInfo`,
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: false, // 返回值是否解密
            data: this.data.merchantForm
        }).then(res => {
            if(res.code == 0){
                wx.showToast({
                    title: '保存成功',
                    icon: 'none',
                    mask: true,
                    duration: 2000
                });
                this.setData({
                    'memberForm.merchantId': res.data,
                    'memberForm.merchantId': res.data,
                    'visitForm.merchantId': res.data,
                    activeIndex: 2
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },

    /**
     * 成员标签
     */
    beMemberTag(e) {
        let { item } =  e.currentTarget.dataset;
        let arr = this.data.memberForm.memberLabel?this.data.memberForm.memberLabel.split(","):[];
        let index = arr.indexOf(item.dictValue);
        console.log(arr,arr.indexOf(item.dictValue))
        if(index == -1){
            arr.push(item.dictValue);
        }else{
            arr.splice(index,1);
        }
        this.setData({
            'memberForm.memberLabel': arr.join(",")
        })
    },

    // 成员信息
    getMerchantPartInfo(){
        request({
            url: "/merchantMarketing/getMerchantPartInfo",
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: true, // 返回值是否解密
            data: {
                id: this.data.form.id
            }
        }).then(res => {
            if(res.code == 0){
                let { form } = this.data;
                for(let key in form){
                    form[key] = res.data[key];
                }
                this.setData({
                    form
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },

    /**
     * 已开通业务、营销重点选择
     */
    onMemberCheckboxChange(e) {
        console.log(e)
        let { key, item } = e.currentTarget.dataset;
        let arr = this.data.memberForm[key]?this.data.memberForm[key].split(","):[];
        let index = arr.indexOf(item.dictValue);
        if(index != -1){
            arr.splice(index,1);
        }else{
            arr.push(item.dictValue);
        }
        this.setData({
            ['memberForm.'+key]: arr.join(",")
        });
    },
    // 保存成员
    saveMember(e) {
        // 传入表单数据，调用验证方法
        if (!this.memberWxValidate.checkForm(this.data.memberForm)) {
            const error = this.memberWxValidate.errorList[0]
            this.showModal(error)
            return false
        }
        if(this.data.memberForm.idCard){
            if(!validateIdent.IdentityCode_isCardNo(this.data.memberForm.idCard)){
                this.showModal({
                    msg: "请输入18位证件号"
                })
                return false
            }
            if(!validateIdent.IdentityCode_checkProvince(this.data.memberForm.idCard)){
                this.showModal({
                    msg: "证件号省份不正确"
                })
                return false
            }
            if(!validateIdent.IdentityCode_checkBirthday(this.data.memberForm.idCard)){
                this.showModal({
                    msg: "证件号出生日期不正确"
                })
                return false
            }
            if(!validateIdent.IdentityCode_checkParity(this.data.memberForm.idCard)){
                this.showModal({
                    msg: "证件号检验位不正确"
                })
                return false
            }
        }
        request({
            url: `/merchantMarketing/addMerchantPartInfo`,
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: false, // 返回值是否解密
            data: this.data.memberForm
        }).then(res => {
            if(res.code == 0){
                wx.showToast({
                    title: '保存成功',
                    icon: 'none',
                    mask: true,
                    duration: 2000
                });
                this.setData({
                    activeIndex: 3
                })
                this.getSysConfigInfo();
                this.getVisitKeynoteList(this.data.mBusiList);
            }
        }).catch(error => {
            // console.log(error)
        })
    },

    /**
     * 获取时间限制
     */
    getSysConfigInfo() {
        request({
            url: "/commonApi/getConfigByMerchantType",
            data: {
                merchantType: 2
            }
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    startDate: util.getDateByNumber(1),
                    endDate: util.getDateByNumber(Number(res.data.configValue)),
                    ['visitForm.reminderDate']: util.getDateByNumber(Number(res.data.configValue)),
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },
    // 拜访图片上传
    uploadVisitImage(e) { // 拍摄或从相册选取上传
        let { key } = e.currentTarget.dataset;
        let that = this;
        let arr = this.data.visitForm.visitPic?this.data.visitForm.visitPic.split(","):[];
        if(arr.length>=5){
            this.showModal({
                msg: "拜访照片最多上传5张"
            })
            return
        }
        wx.chooseImage({
            count: 1, // 默认9
            sizeType: ['compressed'],
            sourceType: ['camera'],
            success(res) {
                wx.compressImage({
                    src: res.tempFilePaths[0], // 图片路径
                    quality: 40, // 压缩质量
                    success(res1) {
                        uploadFile({
                            url: "/commonApi/imageUploadAddWatermark",
                            filePath: res1.tempFilePath,
                            name: "imgfile",
                            formData: {
                                coordinate: that.data.visitForm.coordinate,
                                watermark: that.data.visitForm.mapAddress,
                                fileName: key
                            }
                        }).then(res => {
                            if(res.code == 0){
                                let arr = that.data.visitForm[key]?that.data.visitForm[key].split(","):[];
                                arr.push(res.data)
                                that.setData({
                                    ['visitForm.'+key]: arr.join(",")
                                })
                            }
                        }).catch(error => {
                            // console.log(error)
                        })
                    }
                })
            }
        })
    },
    // 查看图片
    previewVisitImage(e) {
        let { url } = e.currentTarget.dataset;
        let arr = this.data.visitForm.visitPic?this.data.visitForm.visitPic.split(","):[];
        let images = [];
        arr.forEach(item => {
            images.push(this.data.baseUrl+item)
        })
        wx.previewImage({
            current: url, // 当前显示图片的http链接
            urls: images // 需要预览的图片http链接列表
        })
    },

    /**
     * 已开通业务、营销重点选择
     */
    onVisitCheckboxChange(e) {
        console.log(e)
        let { key, item } = e.currentTarget.dataset;
        let arr = this.data.visitForm[key]?this.data.visitForm[key].split(","):[];
        let index = arr.indexOf(item.dictValue);
        if(index != -1){
            arr.splice(index,1);
        }else{
            arr.push(item.dictValue);
        }
        this.setData({
            ['visitForm.'+key]: arr.join(",")
        });
        if(key == "newBusiness"){
            this.getVisitReservationBusiList(this.data.visitKeynoteList);
        }
    },

    // 获取营销重点
    getVisitKeynoteList(list){
        let visitKeynoteList = [];
        let arr = this.data.merchantForm.businessLabel?this.data.merchantForm.businessLabel.split(","):[];
        list.forEach(item => {
            if(arr.indexOf(item.dictValue)==-1){
                visitKeynoteList.push(item)
            }
        })
        this.setData({
            visitKeynoteList
        })
        this.getVisitReservationBusiList(visitKeynoteList);
    },
    getVisitReservationBusiList(list){
        let visitReservationBusiList = [];
        let arr = this.data.visitForm.newBusiness?this.data.visitForm.newBusiness.split(","):[];
        let farr = this.data.visitForm.reservationBusiType?this.data.visitForm.reservationBusiType.split(","):[];
        list.forEach(item => {
            if(arr.indexOf(item.dictValue)==-1){
                visitReservationBusiList.push(item)
            }
        })
        arr.forEach(item => {
            let index = farr.indexOf(item);
            if(index != -1){
                farr.splice(index,1);
            }
        })
        this.setData({
            visitReservationBusiList,
            ['visitForm.reservationBusiType']: farr.join(",")
        })
    },

    // 保存首次拜访
    saveVisit(e) {
        // 传入表单数据，调用验证方法
        if (!this.visitWxValidate.checkForm(this.data.visitForm)) {
            const error = this.visitWxValidate.errorList[0]
            this.showModal(error)
            return false
        }
        if(this.data.visitForm.ecardSemResult == 1){
            if(!this.data.visitForm.newBusiness){
                this.showModal({
                    msg: "请选择本次营销成功"
                })
                return
            }
        }else{
            if(!this.data.visitForm.failReason){
                this.showModal({
                    msg: "请输入失败原因"
                })
                return
            }
        }
        if(!this.data.visitForm.reminderDate){
            this.showModal({
                msg: "请选择下次回访日期"
            })
            return
        }
        if(!this.data.visitForm.hasReservationBusi){
            this.showModal({
                msg: "请选择有无预约业务"
            })
            return
        }
        if(this.data.visitForm.hasReservationBusi == 1){
            if(!this.data.visitForm.reservationBusiType){
                this.showModal({
                    msg: "请选择预约业务"
                })
                return
            }
            if(!this.data.visitForm.appointmentDate){
                this.showModal({
                    msg: "请选择业务预约日期"
                })
                return
            }
        }
        request({
            url: `/merchantMarketing/addMerchantVisitInfo`,
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: false, // 返回值是否解密
            data: this.data.visitForm
        }).then(res => {
            if(res.code == 0){
                wx.showToast({
                    title: '保存成功',
                    icon: 'none',
                    mask: true,
                    duration: 2000
                });
                setTimeout(()=>{
                    wx.navigateBack()
                },2000)
            }
        }).catch(error => {
            // console.log(error)
        })
    },
    // 表单验证
    initMerchantValidate() {
        // 验证字段的规则
        const rules = {
            handName: {
                required: true
            },
            headPic: {
                required: true
            },
            coordinate: {
                required: true
            },
            address: {
                required: true
            },
            industry: {
                required: true
            },
            businessLabel: {
                required: true
            },
        }
        // 验证字段的提示信息，若不传则调用默认的信息
        const messages = {
            handName: {
                required: '请输入门面名称'
            },
            headPic: {
                required: '请上传门面图片'
            },
            coordinate: {
                required: '地图位置'
            },
            address: {
                required: '请输入详细地址'
            },
            industry: {
                required: '请选择所属行业'
            },
            businessLabel: {
                required: '请选择已开通业务'
            },
        }
        // 创建实例对象
        this.merchantWxValidate = new WxValidate(rules, messages)
    },
    // 表单验证
    initMemberValidate() {
        // 验证字段的规则
        const rules = {
            name: {
                required: true
            },
            duties: {
                required: true
            },
            sex: {
                required: true
            },
            phone: {
                required: true,
                tel: true
            },
            // idCard: {
            //     cardNo: true,
            //     checkProvince: true,
            //     checkBirthday: true,
            //     checkParity: true,
            // },
        }
        // 验证字段的提示信息，若不传则调用默认的信息
        const messages = {
            name: {
                required: '请输入姓名'
            },
            duties: {
                required: '请选择职位'
            },
            sex: {
                required: '请选择性别'
            },
            phone: {
                required: '请输入电话',
                tel: '请输入正确的电话'
            },
            // idCard: {
                
            // },
            
        }
        // 创建实例对象
        this.memberWxValidate = new WxValidate(rules, messages)        
    },
    // 表单验证
    initVisitValidate() {
        // 验证字段的规则
        const rules = {
            coordinate: {
                required: true
            },
            visitPic: {
                required: true
            },
            ecardSemResult: {
                required: true
            },
        }
        // 验证字段的提示信息，若不传则调用默认的信息
        const messages = {
            coordinate: {
                required: '打卡定位'
            },
            visitPic: {
                required: '请上传图片'
            },
            ecardSemResult: {
                required: '请选择营销成果'
            },
        }
        // 创建实例对象
        this.visitWxValidate = new WxValidate(rules, messages)
    },
    showModal(error) {
        wx.showToast({
            title: error.msg,
            icon: 'none',
            duration: 2000
        })
    },
})